/**
 * @description 列表页
 * @author xfj
 */

import React, { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Link } from 'react-router-dom';
import { loadData } from '../../share/store/action/list.action';

function List() {
  const dispatch = useDispatch();
  const data = useSelector(state => state.list);
  
  useEffect(() => {
    dispatch(loadData());
  }, [])
  
  return <div>
    <p>返回<Link to='/'>首页</Link></p>
    列表页
    <ul>
      {data?.map(item => (
        <li key={item.id}>{item.title}</li>
      ))}
    </ul>
  </div>
}

function getData(store) {
  return store.dispatch(loadData());
}

export default {
  component: List,
  getData,
};
